package edu.gatech.spacetraderteam3.model;

import java.awt.Color;
import java.util.Random;

import edu.gatech.spacetraderteam3.view.Assets;


/**
 * Prefabricated Solar Systems. Each has a number of properties and about 4 planets per system 
 * @author TBW
 */
public enum SSPrefab { // 31 Solar Systems, 119 Planets. ~4 Planets per solar system.
    // @formatter:off
    SCHOEN      (Assets.SunIcon.SOL, RAND.color(),  1 * Math.PI / 15.5, 300, new SPPrefab[] { SPPrefab.DAMAST, SPPrefab.ENDOR, SPPrefab.OMEGA, SPPrefab.TEROSA }),
    DELFIIN     (Assets.SunIcon.SOL, RAND.color(),  2 * Math.PI / 15.5, 300, new SPPrefab[] { SPPrefab.VAGRA, SPPrefab.PARADE, SPPrefab.KLAATU, SPPrefab.IODINE }),
    LAMINIERUNG (Assets.SunIcon.SOL, RAND.color(),  3 * Math.PI / 15.5, 60, new SPPrefab[] { SPPrefab.DENEB, SPPrefab.FOURMI, SPPrefab.NYLE, SPPrefab.REGULAS }),
    OBST        (Assets.SunIcon.SOL, RAND.color(),  4 * Math.PI / 15.5, 175, new SPPrefab[] { SPPrefab.TURKANA, SPPrefab.MINTAKA, SPPrefab.JAPORI, SPPrefab.FERRIS }),
    ALBERN      (Assets.SunIcon.SOL, RAND.color(),  5 * Math.PI / 15.5, 175, new SPPrefab[] { SPPrefab.XENON, SPPrefab.SIGMA, SPPrefab.LIGON, SPPrefab.BALOSNEE }),
    MOORDENAAR  (Assets.SunIcon.SOL, RAND.color(),  6 * Math.PI / 15.5, 75, new SPPrefab[] { SPPrefab.ADAHN, SPPrefab.QUATOR, SPPrefab.RUBICUM }),
    KEPERCAYAAN (Assets.SunIcon.SOL, RAND.color(),  7 * Math.PI / 15.5, 220, new SPPrefab[] { SPPrefab.STYRIS, SPPrefab.MELINA, SPPrefab.YOJIMBO, SPPrefab.KAYLON }),
    AKVO        (Assets.SunIcon.SOL, RAND.color(),  8 * Math.PI / 15.5, 230, new SPPrefab[] { SPPrefab.HADES, SPPrefab.KRIOS, SPPrefab.MORDAN, SPPrefab.TITAN }),
    LISID       (Assets.SunIcon.SOL, RAND.color(),  9 * Math.PI / 15.5, 180, new SPPrefab[] { SPPrefab.TANTALOS, SPPrefab.PICARD, SPPrefab.MYRTHE, SPPrefab.KRAVAT }),
    KULIGLIG    (Assets.SunIcon.SOL, RAND.color(), 10 * Math.PI / 15.5, 200, new SPPrefab[] { SPPrefab.POLLUX, SPPrefab.STAKORON, SPPrefab.UTOPIA, SPPrefab.JASON }),
    SIYAP       (Assets.SunIcon.SOL, RAND.color(), 11 * Math.PI / 15.5, 250, new SPPrefab[] { SPPrefab.ODET, SPPrefab.SEFALLA, SPPrefab.TRIACUS, SPPrefab.CARZON }),
    DORMIRE     (Assets.SunIcon.SOL, RAND.color(), 12 * Math.PI / 15.5, 200, new SPPrefab[] { SPPrefab.BARATAS, SPPrefab.DENEVA, SPPrefab.NELVANIA, SPPrefab.UMBERLEE }),
    NAKTS       (Assets.SunIcon.SOL, RAND.color(), 13 * Math.PI / 15.5, 300, new SPPrefab[] { SPPrefab.ZUUL, SPPrefab.JARADA, SPPrefab.ANTEDI, SPPrefab.MALCORIA }),
    DUOBLIGI    (Assets.SunIcon.SOL, RAND.color(), 14 * Math.PI / 15.5, 310, new SPPrefab[] { SPPrefab.PENTHARA, SPPrefab.SOMARI, SPPrefab.THERA, SPPrefab.HELENA }),
    GEFAHR      (Assets.SunIcon.SOL, RAND.color(), 15 * Math.PI / 15.5, 200, new SPPrefab[] { SPPrefab.DRAYLON, SPPrefab.ORIAS, SPPrefab.TAMUS, SPPrefab.XERXES }),
    BERJUDI     (Assets.SunIcon.SOL, RAND.color(), 16 * Math.PI / 15.5, 220, new SPPrefab[] { SPPrefab.CASTOR, SPPrefab.JANUS }),
    TERTULIS    (Assets.SunIcon.SOL, RAND.color(), 17 * Math.PI / 15.5, 260, new SPPrefab[] { SPPrefab.IRALIUS, SPPrefab.NIX, SPPrefab.ANDEVIAN, SPPrefab.DALED }),
    SIEMENET    (Assets.SunIcon.SOL, RAND.color(), 18 * Math.PI / 15.5, 120, new SPPrefab[] { SPPrefab.FESTER, SPPrefab.GUINIFER, SPPrefab.LAVE, SPPrefab.ROCHANI }),
    UUPUNUT     (Assets.SunIcon.SOL, RAND.color(), 19 * Math.PI / 16,   230, new SPPrefab[] { SPPrefab.EXO, SPPrefab.MERIK, SPPrefab.RAN, SPPrefab.ACAMAR }),
    VERMOEIDHEID(Assets.SunIcon.SOL, RAND.color(), 20 * Math.PI / 15.5, 180, new SPPrefab[] { SPPrefab.CALONDIA, SPPrefab.SARPEIDON, SPPrefab.DAVLOS, SPPrefab.BRAX }),
    TVIRTUMAS   (Assets.SunIcon.SOL, RAND.color(), 21 * Math.PI / 15.5, 200, new SPPrefab[] { SPPrefab.RHYMUS, SPPrefab.VANDOR, SPPrefab.ESMEE, SPPrefab.MONTOR }),
    MATAPOS     (Assets.SunIcon.SOL, RAND.color(), 22 * Math.PI / 15.5, 210, new SPPrefab[] { SPPrefab.KIRA, SPPrefab.RUTIA, SPPrefab.ZALKON, SPPrefab.HAMLET }),
    ZUHAITZ     (Assets.SunIcon.SOL, RAND.color(), 23 * Math.PI / 15.5, 210, new SPPrefab[] { SPPrefab.ALDEA, SPPrefab.TALANI, SPPrefab.VENTAX, SPPrefab.MENTAR }),
    ABRIC       (Assets.SunIcon.SOL, RAND.color(), 24 * Math.PI / 15.5, 250, new SPPrefab[] { SPPrefab.BRETEL, SPPrefab.DREMA, SPPrefab.TARCHANNEN, SPPrefab.OTHELLO }),
    MERETRIX    (Assets.SunIcon.SOL, RAND.color(), 25 * Math.PI / 15.5, 220, new SPPrefab[] { SPPrefab.KLAESTRON, SPPrefab.CHERON, SPPrefab.OMPHALOS, SPPrefab.VADERA }),
    FERRE       (Assets.SunIcon.SOL, RAND.color(), 26 * Math.PI / 15.5, 250, new SPPrefab[] { SPPrefab.RAKHAR, SPPrefab.TANUGA, SPPrefab.COURTNEY, SPPrefab.CAMPOR }),
    BANGKAY     (Assets.SunIcon.SOL, RAND.color(), 27 * Math.PI / 15.5, 320, new SPPrefab[] { SPPrefab.LAERTES, SPPrefab.SELTRICE, SPPrefab.FROLIX, SPPrefab.TORIN }),
    NABUBULOK   (Assets.SunIcon.SOL, RAND.color(), 28 * Math.PI / 15.5, 390, new SPPrefab[] { SPPrefab.OG, SPPrefab.GEMULON, SPPrefab.CESTUS, SPPrefab.RELVA }),
    SNIGE       (Assets.SunIcon.SOL, RAND.color(), 29 * Math.PI / 15.5, 400, new SPPrefab[] { SPPrefab.TYRUS, SPPrefab.DEVIDIA, SPPrefab.LARGO, SPPrefab.MAGART }),
    ZELTS       (Assets.SunIcon.SOL, RAND.color(), 30 * Math.PI / 15.5, 250, new SPPrefab[] { SPPrefab.HULST, SPPrefab.LOWRY, SPPrefab.KHEFKA, SPPrefab.KORMA }),
    VEIKSME     (Assets.SunIcon.SOL, RAND.color(), 31 * Math.PI / 15.5, 350, new SPPrefab[] { SPPrefab.YEW, SPPrefab.CAPELLE, SPPrefab.SOL });
    //@formatter:on

    /**
     * Used to get a valid random color channel
     * @author TBW
     */
    private static final class RAND {

        /**
         * A numerical random constant
         */
        private static final Random RAND = new Random();
        
        /**
         * Gets a random color value
         * @return a random color value
         */
        public static int cV() {
            return RAND.nextInt(156) + 50;
        }

        /**
         * Gets a random rgb color
         * @return Random RGB color
         */
        public static Color color() {
            return new Color(cV(), cV(), cV(), 200);
        }
    }

    /**
     * Returns random solar system
     * @return A Random Solar System
     */
    public static SSPrefab random() {
        return values()[(int) (Math.random() * values().length)];
    }

    /**
     * the sun's icon
     */
    private Assets.SunIcon sun;

    /**
     * The planets generated in a solarsystem
     */
    private SpacePlanet[] planets;

    /**
     * The color of the solarsystem
     */
    private Color color;

    /**
     * The radious and angle of the system in the galaxy view
     */
    private double radius, theta;

    /**
     * Constructor for Solar Systems
     * @param sun The sun icon to use
     * @param color Color of the system
     * @param theta angle of the system
     * @param radius radius of the system
     * @param planets planets that the system contains
     */
    private SSPrefab(Assets.SunIcon sun, Color color, double theta, double radius,
            SpacePlanet... planets) {
        this.planets = new SpacePlanet[planets.length];
        System.arraycopy(planets, 0, this.planets, 0, planets.length);
        this.sun = sun;
        this.color = color;
        this.radius = radius;
        this.theta = theta;
    }

    /**
     * Constructor for solar systems constructed with prefab planets
     * @param sun Sun icon of the system
     * @param color Color of the sun
     * @param theta Angle of the System
     * @param radius Radius of the system
     * @param prefabs Prefabricated planets contained within the system
     */
    private SSPrefab(Assets.SunIcon sun, Color color, double theta, double radius,
            SPPrefab... prefabs) {
        planets = new SpacePlanet[prefabs.length];
        for (int i = 0; i < prefabs.length; i++) {
            planets[i] = new SpacePlanet(prefabs[i]);
        }
        this.sun = sun;
        this.color = color;
        this.radius = radius;
        this.theta = theta;
    }

    /**
     * Getter for the planets in the system
     * @return The planets in the system
     */
    public SpacePlanet[] planets() {
        return planets;
    }

    /**
     * Getter for the sun icon
     * @return The sun icon
     */
    public Assets.SunIcon sun() {
        return sun;
    }

    /**
     * Getter for the color of the System
     * @return The color
     */
    public Color color() {
        return color;
    }

    /**
     * Getter for the radius of the system
     * @return the radius
     */
    public double radius() {
        return radius;
    }

    /**
     * Getter for the angle of the system
     * @return The angle
     */
    public double theta() {
        return theta;
    }
}
